package study05;

class student1 {
    String name;
    //  属性私有化
    private int age;
    String sex;

//    对私有属性进行封装
//    int getAge() {
//        return age;
//    }

//    设置私有属性的值
    void setAge(int a) {
        if (a >= 18 && a <= 45) {
            age = a;
            System.out.println("你成年了");
        } else if (a >= 0 && a < 18) {
            age = a;
            System.out.println("你是青少年");
        } else if (a > 45 && a <= 60)
        {
            age = a;
            System.out.println("你是中老年");
        }else{
            System.out.println("输入错误，重新输入");
        }
    }

    void read() {
        System.out.println("姓名为：" + name + "," + "今年" + age + "岁" + "," + "正在努力学习...");
    }
}

/**
* @author GZQ
* @Date 2023/11/5
 */

public class Test1 {
    public static void main(String[] args) {
        //对象实例话
        student1 stu1 = new student1();
        student1 stu2 = new student1();
        student1 stu3 = new student1();
        stu1.name = "uyy";
//        调用私有属性类方法
        stu1.setAge(18);
        stu1.sex = "男";
        stu1.read();
        stu2.name = "qqq";
        stu2.setAge(46);
        stu2.sex = "男";
        stu2.read();
        stu3.name = "aaa";
        stu3.setAge(-18);
        stu3.sex = "男";
        stu3.read();
    }
}
